import request from '@/utils/request';
import KEY from './setting'


export function getFontToken(){
  return request({
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    url:'/api/getFontToken',
    method:'post'
  })
}

//取得热门数据
export function getscroll(pagesize,pageindex){
  return request({
    headers: {
      'Content-Type': 'application/json'
    },
    url:'/api/getscroll',
    method:'post',
    data:{
      pagesize:pagesize?pagesize:10,
      pageindex:pageindex?pageindex:1,
      key:KEY.DOUYINKEY
    }
  })
}

//取得日志-分页(懒加载)
export function getsavefont(pagesize,pageindex,fonttype){
  return request({
    headers: {
      'Content-Type': 'application/json'
    },
    url:'/api/getsavefont',
    method:'post',
    data:{
      pagesize:pagesize,
      pageindex:pageindex,
      fonttype:fonttype
    }
  })
}

//取得用户操作日志
export function getuserlog(pagesize,pageindex,datetype,typeid){
  return request({
    headers: {
      'Content-Type': 'application/json'
    },
    url:'/api/userlog',
    method:'post',
    data:{
      pagesize:pagesize,
      pageindex:pageindex,
      datetype:datetype,
      typeid:typeid,
      
    }
  })
}

//保存图片识别的日志
export function savefont(imgpath,content,fonttype){
  return request({
    headers: {
      'Content-Type': 'application/json'
    },
    url:'/api/savefont',
    method:'post',
    data:{
      imgpath:imgpath,
      content:content,
      fonttype:fonttype
    }
  })
}


//看图识字
export function img2font(image,token){
  return request({
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    url:'/api/bdimg2font',
    method:'post',
    data:{
      image,
      token
    },
    //图片base64字符串里有=&等符号，需要转码才能正常传递
    transformRequest: [
      function (data) {
         let ret = ''
         for (let it in data) {
            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
         }
         ret = ret.substring(0, ret.lastIndexOf('&'));
         return ret
      }
    ],
    
  })
}

export function savelog(type,id){
  return request({
    url:'/api/savelog',
    method:'get',
    params:{
      type:type,
      id:id
    }
  })
}



//天气
export function gettq(cityid){
  return request({
    url:'/api/tq',
    method:'get',
    params:{
      city:cityid,
      key:KEY.TQKEY
    }
  })
}
//四川省/成都市/双流区   =>  citylist cityid
export function getcityid(cityfullname){
  return request({
    url:'/api/cityid',
    method:'get',
    params:{
      cityfullname,
    }
  })
}








//取得用户的文字识别类型
export function getfonttype(){
  return request({
    url:'/api/getfonttype',
    method:'get',
    params:{
    }
  })
}
//添加新的识别类型
export function addfonttype(val){
  return request({
    url:'/api/addfonttype',
    method:'get',
    params:{
      name:val
    }
  })
}